﻿#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

class PersonConstFunc
{
public:
	PersonConstFunc()
	{
		//1.构造函数中修改属性，this永远指向本体，实际上指PersonConstFunc* const this；
			//const修饰this后，this不可修改；
		//this = NULL;
		this->m_A = 0;
		this->m_B = 0;
	}

	//void showInfo()
	//2.常函数，不允许修改指针指向的指；即this不能修改后，this->m_A也不能修改；
	void showInfo() const
	{
		//this->m_A = 1000;
		this->m_B = 2000;

		//const PersonConstFunc* const this
		cout << "m_A=" << this->m_A << endl;//0
		cout << "m_B=" << this->m_B << endl;//2000
	}

	void showGeneral()
	{
		m_A = 4000;
	}

	void showGeneralConst() const
	{
		//m_A = 4000;
	}

	int m_A;
	//3.就算是常函数，还是要执意修改，就加上关键字mutable；
	mutable int m_B;
};
void testConstFunc()
{
	PersonConstFunc p1;
	p1.showInfo();

	//4.常对象，不允许修改属性；不可以调用普通成员函数showGeneral()；可以调用常函数showGeneralConst()；
	const PersonConstFunc p2;
	//p2.m_A = 3000;
	cout << p2.m_A << endl;//0
	//p2.showGeneral();
	p2.showGeneralConst();
}

//main272：const修饰成员函数
int main272()
{
	testConstFunc();

	system("pause");
	return EXIT_SUCCESS;
}